package org.apaydin.beyazperde;

import org.apaydin.CalendarUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Week {

    private final Calendar calendar;

    private final String urlString;

    private final String weekString;

    private final String toString;

    public Week(Calendar calendar) {
        this.calendar = calendar;
        calendar.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
        urlString = new SimpleDateFormat("yyyy-MM-dd").format(calendar.getTime());
        weekString = calendar.get(Calendar.WEEK_OF_YEAR) + ". Hafta";
        toString = weekString + " (" + new SimpleDateFormat("dd/MM/yyyy").format(calendar.getTime()) + ")";
    }

    public Week(Date date) {
        this(CalendarUtils.toCalendar(date));
    }

    public String toUrlString() {
        return urlString;
    }

    public Week nextWeek(){
        Calendar c = CalendarUtils.toCalendar(calendar.getTime());
        c.add(Calendar.WEEK_OF_YEAR, 1);
        return new Week(c);
    }

    public Week previousWeek(){
        Calendar c = CalendarUtils.toCalendar(calendar.getTime());
        c.add(Calendar.WEEK_OF_YEAR, -1);
        return new Week(c);
    }

    public Week addWeek(int week){
        Calendar c = CalendarUtils.toCalendar(calendar.getTime());
        c.add(Calendar.WEEK_OF_YEAR, week);
        return new Week(c);
    }

    public String toString() {
        return toString;
    }

    public String getWeekString(){
        return weekString;
    }

}
